package com.eugenema.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.eugenema.util.ExcelUtil.DirectionConverter;
import com.eugenema.util.ExcelUtil.EvenMatchConverter;
import com.eugenema.util.ExcelUtil.TeamConverter;

import java.util.Date;

/**
 * 实体类：未来比赛信息
 *
 * @author Eugenema
 * @date 2023-03-01 10:21
 */
public class FutureMatch {
    /**
     * 方向：双
     */
    public static final String DIRECTION_DOUBLE = "双";
    /**
     * 方向：单
     */
    public static final String DIRECTION_SINGLE = "单";

    /**
     * 联赛
     */
    @ExcelProperty("联赛")
    private String league;
    /**
     * 时间
     */
    @ExcelProperty("时间")
    @DateTimeFormat("yyyy/MM/dd hh:mm")
    private Date dataTime;
    /**
     * 主队
     */
    @ExcelProperty(value = "主队", converter = TeamConverter.class)
    private Team masterTeam;
    /**
     * 常量，以便 Excel 模板填充
     */
    @ExcelProperty("VS")
    private String vs = "VS";
    /**
     * 客队
     */
    @ExcelProperty(value = "客队", converter = TeamConverter.class)
    private Team guestTeam;
    /**
     * 盘口
     */
    @ExcelProperty("盘口")
    private String handicap;
    /**
     * 目标球队
     */
    @ExcelProperty(value = "目标球队", converter = TeamConverter.class)
    private Team targetTeam;
    /**
     * 方向：true 为双，false 为单
     */
    @ExcelProperty(value = "方向", converter = DirectionConverter.class)
    private Boolean direction;
    /**
     * 连场
     */
    @ExcelProperty(value = "连场", converter = EvenMatchConverter.class)
    private EvenMatch evenMatch;
    /**
     * 常量，以便 Excel 模板填充
     */
    @ExcelProperty("赔率")
    private String odds = "";

    public String getLeague() {
        return league;
    }

    public void setLeague(String league) {
        this.league = league;
    }

    public Date getDataTime() {
        return dataTime;
    }

    public void setDataTime(Date dataTime) {
        this.dataTime = dataTime;
    }

    public Team getMasterTeam() {
        return masterTeam;
    }

    public void setMasterTeam(Team masterTeam) {
        this.masterTeam = masterTeam;
    }

    public Team getGuestTeam() {
        return guestTeam;
    }

    public void setGuestTeam(Team guestTeam) {
        this.guestTeam = guestTeam;
    }

    public String getHandicap() {
        return handicap;
    }

    public void setHandicap(String handicap) {
        this.handicap = handicap;
    }

    public Team getTargetTeam() {
        return targetTeam;
    }

    public void setTargetTeam(Team targetTeam) {
        this.targetTeam = targetTeam;
    }

    public Boolean getDirection() {
        return direction;
    }

    public void setDirection(Boolean direction) {
        this.direction = direction;
    }

    public EvenMatch getEvenMatch() {
        return evenMatch;
    }

    public void setEvenMatch(EvenMatch evenMatch) {
        this.evenMatch = evenMatch;
    }

    public String getVs() {
        return vs;
    }

    public void setVs(String vs) {
        this.vs = vs;
    }

    public String getOdds() {
        return odds;
    }

    public void setOdds(String odds) {
        this.odds = odds;
    }

    @Override
    public String toString() {
        return "未来比赛信息：{" +
                "联赛='" + league + '\'' +
                ", 时间='" + dataTime + '\'' +
                ", 主队=" + masterTeam +
                ", 客队=" + guestTeam +
                ", 盘口='" + handicap + '\'' +
                ", 目标球队='" + targetTeam + '\'' +
                ", 方向=" + directionConverter(direction) +
                ", 连场=" + evenMatch +
                '}';
    }

    /**
     * “方向”字段，字符串与布尔类型的相互转换
     *
     * @param converterValue 需要转换的数据
     *
     * @author Eugenema
     * @date 2023/3/5 18:35
     *
     * @return 转换后的数据，若参数类型非法，则返回 false
     **/
    public static Object directionConverter(Object converterValue) {
        if (converterValue instanceof Boolean) {
            return (Boolean) converterValue ? FutureMatch.DIRECTION_DOUBLE : FutureMatch.DIRECTION_SINGLE;
        } else if (converterValue instanceof String) {
            return FutureMatch.DIRECTION_DOUBLE.equals(converterValue) ? Boolean.TRUE : Boolean.FALSE;
        } else {
            return Boolean.FALSE;
        }
    }
}
